USE [SilkeyERP]
GO

DECLARE @Total DECIMAL(18,7)
DECLARE @SubTotal DECIMAL(18,7)
DECLARE @ID INT
SET @Total = RAND()*(10-1)+1;
SET @SubTotal = @Total /1.21

INSERT INTO [dbo].[Sales]
           ([Number]
           ,[Code]
           ,[CustomerID]
           ,[SalesPersonID]
           ,[SalesPriceListID]
           ,[CreateDate]
           ,[ModificationDate]
           ,[CloseDate]
           ,[StatusID]
           ,[Total]
           ,[SubTotal]
           ,[DiscountAmount]
           ,[TaxID]
           ,[Enable])
     VALUES
           (3
           ,1
           ,8
           ,1
           ,1
           ,GetDate()
           ,NULL
           ,GetDate()
           ,2
           ,@Total
           ,@SubTotal
           ,0
           ,1
           ,1)

SELECT @ID = SCOPE_IDENTITY()

INSERT INTO [dbo].[SalesDetails]
           ([SalesID]
           ,[ProductID]
           ,[TaxID]
           ,[CurrentPriceWTax]
           ,[CurrentPriceWOutTax]
           ,[Quantity]
           ,[DiscountAmount]
           ,[CreateDate]
           ,[ModificacionDate]
           ,[Enable])
     VALUES
           (@ID
           ,2
           ,1
           ,(SELECT [CurrentPriceWTax] FROM [dbo].[SalesPriceListDetails] WHERE [SalesPriceListDetailsID] = 1) 
           ,(SELECT [CurrentPriceWOutTax] FROM [dbo].[SalesPriceListDetails] WHERE [SalesPriceListDetailsID] = 1) 
           ,2
           ,0
            ,GetDate()
           ,NULL
           ,1)
GO




